package com.gy.service.impl;


import com.aaa.entity.DictData;
import com.aaa.vo.Result;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.gy.mapper.DictTypeMapper;
import com.gy.service.DictDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author GaoYa
 * @Date 2023/3/24 16:24
 * @Version 1.5
 */
@Service
public class DictDataServiceImpl implements DictDataService {
    @Autowired(required = false)
    private DictTypeMapper dictTypeDao;

    @Autowired
    private StringRedisTemplate redisTypeDao;

    /**
     * 跟据前端传过来的类型跟字典表比较，使其返回字典表数据
     * @param type
     * @return
     */
    @Override
    public Result<List<DictData>> findAllByType(String type) {
//        try {
//            String s = redisTypeDao.opsForValue().get(type);
//            if (StringUtils.hasText(s)){
//                List<DictData> dictData = JSON.parseArray(s, DictData.class);
//                return new Result<>(2000,"查询成功",dictData);
//            }
//        }catch (Exception e) {
//            e.printStackTrace();
//        }
        QueryWrapper<DictData> queryWrap = new QueryWrapper<>();
        queryWrap.eq("dict_type",type);
        List<DictData> dictTypes = dictTypeDao.selectList(queryWrap);
        return new Result<>(2000,"查询成功",dictTypes);
    }
}
